import React from 'react';
import { inject, observer} from 'mobx-react';
import {Spin,Button,Modal,Tooltip} from 'antd';
import { WeaTableNew } from "comsMobx";
import { WeaTop,WeaDialog,WeaLocaleProvider,WeaRightMenu,WeaPopoverHrm,WeaRadioGroup,WeaProgress} from 'ecCom';
import * as Util from '../../../util/Util'
import AuthIndex from './AuthIndex'
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;
const toJS = mobx.toJS;
@inject('taskExportStore')
@observer
export default class ExportIndex extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        _height:Util.getCurrentHeight(),
        collectParams :{
          favname: getLabel(520758,'任务导出'),
          favouritetype: 5,
          link: '/spa/workrelate/static/index.html#/main/workrelate/task/taskIndex?condtype=10',
          importantlevel: 1,
        },
        currentmenu:[{key: '0',icon: <i className='icon-coms-export' />,content: getLabel(17416,'导出'),
        onClick: key => this.doExportData()},
       {key: '1',icon: <i className='icon-coms-Custom'/>,content : getLabel(32535,'显示列定制'),
        onClick : this.showColumn}],
        authVisiable:false
      }
    }
    componentWillMount() {//一些初始化请求
      Util.setWindowKeys(10,getLabel(520758,'任务导出'));
      const {taskExportStore} = this.props;
      taskExportStore.doInit();
    }
    showColumn = () => {//显示列定制
      const {taskExportStore: { tableStore }} = this.props;
      tableStore.setColSetVisible(true);
      tableStore.tableColSet(true);
    }
    getRightButton(ecId){
      const {hasRight,operateExport} = this.props.taskExportStore;
      let menu = [];
      menu.push(<Tooltip ecId={`${ecId}_Tooltip@zzfmln@exportdata`} title={getLabel(17416,'导出')}><Button ecId={`${ecId}_Button@uteof6@exportdata`} type='primary' onClick={()=>operateExport()}>{getLabel(17416,'导出')}</Button></Tooltip>);
      if(hasRight){
        menu.push(<Tooltip ecId={`${ecId}_Tooltip@l4sqn1@authset`} title={getLabel(16526,'权限设置')}><Button ecId={`${ecId}_Button@ambise@authset`} type='primary' onClick={()=>this.authVisable(true)}>{getLabel(16526,'权限设置')}</Button></Tooltip>);
      }
      return menu;
    }
    doExportData(){
      const {operateExport} = this.props.taskExportStore;
      operateExport();
    }
    authVisable(flag){
      this.setState({authVisiable:flag});
    }
    getColumns = columns => {
      return columns.map(col => {
          if (col.dataIndex == "taskprogress") {
              return {
                  ...col,
                  render: (text, record, index) => {
                      return <WeaProgress ecId={`${this && this.props && this.props.ecId || ''}_WeaProgress@suqeyr@${record.id}`} percent={text || "0"} strokeColor={text == 100 ? "#68D358" : "#2DB7F5"}/>
                  }
              };
          }
          return col;
      });
    }
    render() {
      const {_height,collectParams,currentmenu,authVisiable} = this.state;
      const {spinloading,conditionInfo,updateRadioGroupParams,tableStore} = this.props.taskExportStore;
      return (
        <div className="wea-workrelate-task-taskexport" style={{height:_height}}>
          <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@9ts678`} spinning={spinloading}>
          <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@b1mcki`}/>
          <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@j4e14y`} datas={currentmenu} showUrlItem={false} style={{height:'100%'}} collectParams={collectParams}>
              <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@ivwbhj`}
                title={getLabel(520758,'任务导出')}
                icon={<i className='icon-coms-implement' />}
                iconBgcolor='rgb(150, 53, 138)'
                buttons = {this.getRightButton(this.props.ecId || '')}
                showDropIcon={true}
                dropMenuDatas = {currentmenu}/>
              <WeaRadioGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaRadioGroup@ctg66n`} config={conditionInfo}  beforeInit={(a,b,c)=>{c(b);}}  onChange={(params)=> {updateRadioGroupParams(params);}}/>
              <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@pi04ne`}
                  comsWeaTableStore={tableStore}
                  hasOrder = {true}
                  getColumns={this.getColumns}
                  needScroll = {true}/>
            </WeaRightMenu>
          {authVisiable &&<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@vtu10n`}
              icon="icon-coms-implement"
              iconBgcolor='rgb(150, 53, 138)'
              onCancel={() =>this.authVisable(false)}
              title={getLabel(16526, '权限设置')}
              visible={authVisiable}
              buttons={[<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@vpwsdl@close`} type="ghost" onClick={()=>this.authVisable(false)}>{getLabel(309, '关闭')}</Button>]}
              style={{ width: 900, height: 580 }}>
              <AuthIndex ecId={`${this && this.props && this.props.ecId || ''}_AuthIndex@xpqoq7`} type="1"/>
          </WeaDialog>}
          </Spin>
        </div>
    )
  }
};